package UIComponents// ActionScript file
{
	import MyComponent.MyButton;
	
	import fl.events.ComponentEvent;
	
	import flash.display.DisplayObject;
	import flash.display.DisplayObjectContainer;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	public class UIPackage extends Sprite
	{
		private var _wishItemList:DisplayObject;
		private var _itemList:DisplayObject;
		private var _collectItemList:DisplayObject;
		
		public var _button_common:MyButton;
		//		public var _button_weapon:MyButton;
		public var _button_collect:MyButton;
		//		public var _button_medicinal:MyButton;
		
		public function UIPackage():void
		{
			this.init();
		}
		
		private function init():void
		{
			this._wishItemList=this.getChildByName("layer_wishItemList");
			this._itemList=this.getChildByName("layer_itemList");
			this._collectItemList=this.getChildByName("layer_collectItemList");
			
			this._button_common=this.getChildByName("button_common") as MyButton;
			//			this._button_weapon=this.getChildByName("button_weapon") as MyButton;
			this._button_collect=this.getChildByName("button_collect") as MyButton;
			//			this._button_medicinal=this.getChildByName("button_medicinal") as MyButton;
			
			this.addListener();
			this.showCommonItems();
			
			//Q币显示
			this.getChildByName("moneySp").visible=FlatInfo.isOpenSeeQb;
			this.getChildByName("txt_myOB").visible=FlatInfo.isOpenSeeQb;
			this.getChildByName("button_addOB").visible=FlatInfo.isOpenSeeQb;
			this.getChildByName("qqmoneybg").visible=FlatInfo.isOpenSeeQb;
		}
		
		public function controlMoenyIcon(qb:Boolean=true):void
		{
			var ms:DisplayObjectContainer=this.getChildByName("moneySp") as DisplayObjectContainer;
			ms.getChildByName("qdian").visible=qb;
			ms.getChildByName("obIcon").visible=!qb;
			ms.visible=FlatInfo.isOpenSeeQb;
			this.getChildByName("button_addOB").visible=FlatInfo.isOpenSeeQb;
		}
		//new guide start
		public function get duihuaBtn():DisplayObject
		{
			return (this._collectItemList as ListCollectItems).getListCollectSuitByIndex(0)["exchangeBtn"];
		}
		//new guide end
		
		private function addListener():void
		{
			(this.getChildByName("button_close") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,closeHandler);
			(this.getChildByName("button_addJB") as MyButton).addEventListener(ComponentEvent.BUTTON_DOWN,addJBHandler);
			(this.getChildByName("spWish") as Sprite).buttonMode	=	true;
			(this.getChildByName("spWish") as Sprite).addEventListener(MouseEvent.CLICK,wishClickHandler);
			( (this.getChildByName("layer_wishItemList") as Sprite).getChildByName("button_wish") as Sprite).addEventListener(MouseEvent.CLICK,wishClickHandler);
			
			(this.getChildByName("layer_itemList") as Sprite).addEventListener("clickWishBtn",wishClickHandler);
			(this.getChildByName("layer_collectItemList") as Sprite).addEventListener("clickCollectWish",wishClickHandler);
		}
		
		private function removeListener():void
		{
			
			(this.getChildByName("button_close") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,closeHandler);
			(this.getChildByName("button_addJB") as MyButton).removeEventListener(ComponentEvent.BUTTON_DOWN,addJBHandler);
			(this.getChildByName("spWish") as Sprite).removeEventListener(MouseEvent.CLICK,wishClickHandler);
			( (this.getChildByName("layer_wishItemList") as Sprite).getChildByName("button_wish") as Sprite).removeEventListener(MouseEvent.CLICK,wishClickHandler);
			(this.getChildByName("layer_itemList") as Sprite).removeEventListener("clickWishBtn",wishClickHandler);		
		}
		
		private function addJBHandler(e:ComponentEvent):void
		{
			if(FlatInfo.isOpenExchangMoney)
			{
				this.dispatchEvent(new PanelEvent("showExChangePanel",true));
			}
		}
		
		public function showMyJB(value:int):void
		{
			(this.getChildByName("txt_myJB") as TextField).text=String(value);
		}
		
		public function showMyOB(value:int):void
		{
			(this.getChildByName("txt_myOB") as TextField).text=String(value);
		}
		
		
		
		private function showCommonItems():void
		{
			this.hideAll();
			this.itemList.visible=true;
		}
		
		private function hideAll():void
		{
			this.itemList.visible=false;
			this.collectItemList.visible=false;
		}
		
		private function closeHandler(e:ComponentEvent):void
		{
			this.dispatchEvent(new PanelEvent(PanelEvent.CLOSE,true));
		}
		
		private function wishClickHandler(e:Event):void
		{
			this.dispatchEvent(new Event("clickWish",true));
		}
		
		public function setItemsAry(itemsAry:Array):void
		{
			(this.itemList as ListUseItems).setItemsAry(itemsAry);
		}
		
		/**
		 * 给收藏物品赋值 
		 * @param itemsArr
		 */		
		public function setCollectionArr(itemsArr:Array):void
		{
			(this.collectItemList as ListCollectItems).setItemsAry(itemsArr);
		}
		
		public function release():void
		{
			
		}
		
		/*getter & setter*/
		public function get wishItemList():DisplayObject
		{
			return _wishItemList;
		}
		
		public function get itemList():DisplayObject
		{
			return _itemList;
		}
		
		public function get collectItemList():DisplayObject
		{
			return _collectItemList;
		}
		
		
		
		
	}
}